<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page pageEncoding="UTF-8"%>
<%@ page session="false"%>


<%@page import="com.matu.controller.HomeController"%>
<%@page import="com.matu.util.HTMLComboBox"%>
<%@page import="com.matu.util.ToolBox"%>
<%@page import="com.matu.domain.Ligne"%>
<%@page import="com.matu.domain.Arret"%>
<%@page import="java.util.ArrayList"%>

<!DOCTYPE html>
<html>
<head>

<title>WST Project - Déplacez vous!</title>

<!-- meta -->
<meta name="description" content="">
<meta name="author" content="M. Steve">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?xml version="1.0" encoding="ISO8859-1" ?>

<!-- mon icon -->
<link rel="shortcut icon" href="favicon.ico">

<!-- mon template.css -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/resources/css/main.css"
	type="text/css" media="screen">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/resources/css/menu.css"
	type="text/css" media="screen">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/resources/css/inputs.css"
	type="text/css" media="screen">



</head>

<body onLoad="init()">
	<header>
		<!-- menu du haut -->
		<nav>
			<ul id="menu">
				<li>
					<a href="home">
						<img
						src="${pageContext.request.contextPath}/resources/images/logo.bmp"
						style="vertical-align: middle;" />
					</a>
				</li>
				<li style="margin-left: 50px"><a href="home">Métro/Bus</a></li>
				<li><a href="velo">Vélo</a></li>
				<li><a href="monTrajet">Mon Trajet</a></li>
			</ul>
		</nav>
	</header>
	<!-- Banière -->
	<div id="banner"
		style="background-image:url(${pageContext.request.contextPath}/resources/images/bannerAcceul.jpg);">
		<br/> <br/> <br/> <br/> <br/> <br/> <br/>
		<br/> <br/> <br/>
		<h1 class="headerTitle">WST PROJECT</h1>
	</div>


	<!-- Corp  -->
	<div id="corp">



		<br/>

		<!-- article n°2 -->
		<div id="descrition">
			<form name="input" action="" method="get">
				<h3>Trouver un bus ou un métro</h3>
				<p> 
	
					<select class="textbox" onchange='this.form.submit()' onMouseOver="hide()" style='width:300px;height:40px;' name="idLigne">
						<% 	
							
							String idSelectedLigne = (String)request.getParameter("idLigne");
							if (idSelectedLigne == null) idSelectedLigne = "-1";
						
							out.print("<option id='titre' value=\'"+"-1"+"\'>" + "Choisissez votre ligne" + "</option>");
					
							@SuppressWarnings("unchecked")
							ArrayList<Ligne> listeDesLignes = (ArrayList<Ligne>) request.getAttribute("listLigne");
							
							for (int i=0; i<listeDesLignes.size(); i++) {
								Ligne ligne = listeDesLignes.get(i);
								
								if (idSelectedLigne.equals(ligne.getId())) out.print("<option selected value='"+ligne.getId()+"\'>" + ligne.getNom() + "</option>");
								else out.print("<option value=\'"+ligne.getId()+"\'>" + ligne.getNom() + "</option>");
							}
						%>
					</select>
					
					<% 
						
						if (!idSelectedLigne.equals("-1")) {
							
							Ligne ligneBD = (Ligne) request.getAttribute("ligneBD");
							double nbLikes = 0;
							double minLike = 0;
							double maxLike = 0;
							
							if (ligneBD != null) {
								nbLikes = ligneBD.getNbLikes();
								minLike = -ligneBD.getNbLikesTotal();
								maxLike = ligneBD.getNbLikesTotal();
								if(nbLikes == minLike) nbLikes = minLike + 0.2;
							}
							
							String images = "";
							images += "<br/><br/>";
							images += " <meter style='width:200px;' high='0' optimum='"+maxLike+"' low='0' min='"+minLike+"' max='"+maxLike+"' value='" + nbLikes + "'></meter> ";
							images += "<a style='text-decoration:none;' href='addLike?idLigne="+idSelectedLigne+"&like=yes'>";
							images += "<img src='"+ request.getContextPath() +"/resources/images/pouce vert.png'  style='width:25px;height:25px;vertical-align: middle;' /> </a>"; 
							images += "<a style='text-decoration:none;' href='addLike?idLigne="+idSelectedLigne+"&like=no'>";
							images += "<img src='"+ request.getContextPath() +"/resources/images/pouce rouge.png' style='width:25px;height:25px;vertical-align: middle;' /> </a>";
							images += " ( "+ (int)maxLike +" votes )";
							out.print(images);
						}
					%>
				</p>
			 
				
				<p>
					<br/>
					<% 
						if (!idSelectedLigne.equals("-1")) {
							
							@SuppressWarnings("unchecked")
							ArrayList<Arret> listeDesArrets = (ArrayList<Arret>) request.getAttribute("listArret");
							String listArr = "";
							
							if (listeDesArrets.isEmpty()) {
								out.print("Aucun arrets sur cette ligne.");
							}
		
							for (Arret a: listeDesArrets) {

								listArr += "<a href='horaireLigne?idArret=" + a.getIdent() + "&idLigne="+idSelectedLigne+"' >" ;
								listArr += "<p><img  src= '" + request.getContextPath() +"/resources/images/fleche.png' ";
								listArr += "style='vertical-align: middle;' />";
								listArr += a.getNom() + " -> " + a.getDestination() ;
								listArr += "</p>";
								listArr += "</a>";
							}
							
							out.print(listArr);
						
						}
					
			
					%>
				</p>


	
				<div align="left"></div>

			</form>
		</div>
		<!-- SocialBox -->
		<div id="social">

			<div class="socialBox">
			
				<%
					String username = (String) request.getSession().getAttribute("user");
				
					if (username != null){
						out.print("<h2>"+username+"</h2>");
					}
					else{
						out.print("<h2>PROFIL</h2>");
					}
				%>
	
				<p style="text-align:center;">
					<img
						src="${pageContext.request.contextPath}/resources/images/avatar_icon.jpg"
						width="190" height="210">
				</p>

				<div style="text-align:center;">
				
				<%
					String myForm = "";
				
					if (username == null){
						myForm += "<form action='connexion' method='post'>";
						myForm +="Votre pseudo <input type='text' name='id'><br>";
						myForm +="Votre mot de passe<input type='password' name='password'><br>";
						myForm +="<input type='submit' value='Connexion' width=250 class='coolButton'>";
						myForm +="</form>";
					}
					else{
						myForm += "<form action='connexion' method='post'>";
						myForm += "<input type='hidden' name='deconnexion'><br>";
						myForm +="<input type='submit' value='Deconnexion' name='deconnexion' width=250 class='coolButton'>";
						myForm +="</form>";
					}
					
					out.print(myForm);
					
				%>
				</div>


			</div>


		</div>



	</div>
	<!-- /SocialBox -->

	<!-- foot -->
	<div style="text-align:center;" id="foot">
		Magras Steve, Paul Tudou , 2014
	</div>

	<script type="text/javascript">
		function hide()
		{
			document.getElementById('titre').style.display = 'none';
		}
	</script>
</body>

</html>